package com.kj.tms.system.service.menu.serviceImpl;


import com.kj.pagehelper.Page;
import com.kj.tms.common.bean.dto.ReturnData;
import com.kj.tms.common.utils.constant.Consts;
import com.kj.tms.pri.system.menu.dto.LogDTO;
import com.kj.tms.pri.system.menu.service.LogService;
import com.kj.tms.system.service.menu.dao.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class LogServiceImpl implements LogService {

    @Autowired
    private LogMapper logMapper;

    @Override
    public void add(LogDTO logDTO) {
        logMapper.add(logDTO);
    }

    @Override
    public ReturnData queryByPageInfo(@RequestBody LogDTO model) {
        //设置页面数据
        Map<String, Object> returnObject = new HashMap<String, Object>();
        Page page = new Page(model.getPage(), model.getRows());
        model.setBeginIndex(page.getStartRow());
        model.setEndIndex(page.getEndRow());
        List<LogDTO> dsList = logMapper.listByPage(model);
        int total = logMapper.getTotalCounts(model);
        returnObject.put("total", total);
        returnObject.put("rows", dsList);
        return new ReturnData(Consts.SUCCESS, "", returnObject);
    }

    @Override
    public List<LogDTO> queryByPage(@RequestBody LogDTO model) {
        return logMapper.listByPage(model);
    }

    @Override
    public int getTotalCounts(@RequestBody LogDTO model) {
        return logMapper.getTotalCounts(model);
    }
}
